import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
import app from './modules/app'
import getters from './getters'

import moduleA from '@/store/modules/vuexModulesTest/moduleA'
import moduleB from '@/store/modules/vuexModulesTest/moduleB'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    permission:
      'ControlPanel|BannerSetting|GoodsSetting|ProductSetting|RecommendSetting|ClassiFication|GoodsManager',
    vueObservable: Vue.observable({ name: '张三', age: 39 }),
    userinfo: { name: '张三1', age: 30 },
    // test module
    logined: false,
    isVip2: false
  },
  mutations: {
    changeVueObservableName(state, name) {
      state.vueObservable.name = name
    },
    changeVueObservableAge(state, age) {
      state.vueObservable.age = age
    },
    // 没有使用 Vue.observable
    changeUserInfoName(state, name) {
      state.userinfo.name = name
    },
    changeUserInfoAge(state, age) {
      state.userinfo.age = age
    },
    // 测试module
    UPDATE_LOGIN_STATUS: (state, payload) => {
      state.logined = true
    },
    UPDATE_TO_VIP2: (state, payload) => {
      state.isVip2 = !state.isVip2
    }
  },
  modules: {
    // 注册这个模块
    app,
    moduleA,
    moduleB
  },
  getters,
  // https://blog.csdn.net/m0_60009963/article/details/122001076
  plugins: [createLogger()] // 日志监听 每一次使用vuex 都能观察到数据的使用 mutation
})

/*
全部权限代码
  控制面板 ControlPanel
  首页设置
    轮播图 BannerSetting
    热销商品 GoodsSetting
    新品上线 ProductSetting
    为你推荐 RecommendSetting
  分类管理 ClassiFication
  商品管理 GoodsManager
  会员管理 MemberManager
  订单管理 OrderManager
  系统设置 SystemSetting
*/
